<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="inc.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主页</title>
<script type="text/javascript">
	var index_layout;
	var index_tabs;
	var index_tabsMenu;
	var layout_west_tree;
	var layout_west_tree_url = '';
	
	var sessionInfo_userId = '${sessionInfo.id}';
	if (sessionInfo_userId) {//如果没有登录,直接跳转到登录页面
		layout_west_tree_url = '${ctx}/resource/tree';
	}else{
		window.location.href='${ctx}/admin/index';
	}
	$(function() {
		var date = new Date();
		var d = date.getDate();
		var m = date.getMonth() + 1;
		var y = date.getFullYear();
		var yyyyMMdd = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d); 
		
		var dateTomorrow = new Date(date.getFullYear(),date.getMonth(),date.getDate() + 1);
		var d1 = dateTomorrow.getDate();
		var m1 = dateTomorrow.getMonth() + 1;
		var y1 = dateTomorrow.getFullYear();
		var yyyyMMddTomorrow = y1 + "-" + (m1 < 10 ? "0" + m1 : m1) + "-" + (d1 < 10 ? "0" + d1 : d1); 
		
		var dateAfterTomorrow = new Date(date.getFullYear(),date.getMonth(),date.getDate() + 2);
		var d2 = dateAfterTomorrow.getDate();
		var m2 = dateAfterTomorrow.getMonth() + 1;
		var y2 = dateAfterTomorrow.getFullYear();
		var yyyyMMddAfterTomorrow = y2 + "-" + (m2 < 10 ? "0" + m2 : m2) + "-" + (d2 < 10 ? "0" + d2 : d2); 
		//$("td").attr("bgcolor", '#CCCCCC').append("<center class=\"timeTomorrow\"></center>");
		//$('.timeTomorrow').eq(0).append("【休假】");
	    $.post('${ctx}/user/showPeopleHolidayStatus',{}, function(events){
			var objs = jQuery.parseJSON(events);
			if(objs.success){
				for ( var i = 0; i < objs.obj.length; i++) {
					var list = objs.obj[i];
					if (i == 0) {
						for ( var j = 0; j < list.length; j++) {
							testNoonOrAfternoon(list[j],yyyyMMdd,'.timeNow');
						}
					}
					if (i == 1) {
						for ( var j = 0; j < list.length; j++) {
							testNoonOrAfternoon(list[j],yyyyMMddTomorrow,'.timeTomorrow');
						}
					}
					if (i == 2) {
						for ( var j = 0; j < list.length; j++) {
							testNoonOrAfternoon(list[j],yyyyMMddAfterTomorrow,'.timeAfterTomorrow');
						}
					}
				}
			}
		});

		function testNoonOrAfternoon(listJ, yyyyMMddStr, time){   
			if (listJ.startTime.substr(0,10) == yyyyMMddStr && listJ.endTime.substr(0,10) == yyyyMMddStr) {//判断起始截止时间是否当天
				$(time).eq(0).append("【" + listJ.name + ":休假:"+ listJ.startTime + "至" + listJ.endTime +"】<br>");
			}else if(listJ.startTime.substr(0,10) != yyyyMMddStr && listJ.endTime.substr(0,10) == yyyyMMddStr){//不是当天
				$(time).eq(0).append("【" + listJ.name + ":休假:"+ listJ.startTime + "至" + listJ.endTime +"】<br>");
			}else if(listJ.startTime.substr(0,10) == yyyyMMddStr && listJ.endTime.substr(0,10) != yyyyMMddStr){
				$(time).eq(0).append("【" + listJ.name + ":休假:"+ listJ.startTime + "至" + listJ.endTime +"】<br>");
			}else{
				$(time).eq(0).append("【" + listJ.name + ":休假:"+ listJ.startTime + "至" + listJ.endTime +"】<br>");
			}
		}
		 
		var myDate = new Date(); 
		var timeNow = new Date();
	 	var Week = ['日','一','二','三','四','五','六']; 
		$('#today').html("[今天] " + (myDate.getMonth() + 1) + "月" + myDate.getDate() + "日  " + "星期" + Week[myDate.getDay()]);
		myDate.setDate(myDate.getDate() + 1);
		$('#tomorrow').html((myDate.getMonth() + 1) + "月" + myDate.getDate() + "日  " + "星期" + Week[myDate.getDay()]);
		myDate.setDate(myDate.getDate() + 1);
		$('#thedayaftertomorrow').html((myDate.getMonth() + 1) + "月" + myDate.getDate() + "日  " + "星期" + Week[myDate.getDay()]);
		if (timeNow.getHours() >= 9) {
			//$('.timeNow').eq(timeNow.getHours() - 9).html("当前时刻 " + timeNow.getHours() + ":" + (timeNow.getMinutes() < 9 ? "0" + timeNow.getMinutes() : timeNow.getMinutes()));
		}
		index_layout = $('#index_layout').layout({
			fit : true
		});
		
		index_tabs = $('#index_tabs').tabs({
			fit : true,
			border : false,
			tools : [{
				iconCls : 'icon_home',
				handler : function() {
					index_tabs.tabs('select', 0);
				}
			}, {
				iconCls : 'icon_refresh',
				handler : function() {
					var index = index_tabs.tabs('getTabIndex', index_tabs.tabs('getSelected'));
					index_tabs.tabs('getTab', index).panel('refresh');
				}
			}, {
				iconCls : 'icon_del',
				handler : function() {
					var index = index_tabs.tabs('getTabIndex', index_tabs.tabs('getSelected'));
					var tab = index_tabs.tabs('getTab', index);
					if (tab.panel('options').closable) {
						index_tabs.tabs('close', index);
					}
				}
			} ]
		});
		
		layout_west_tree = $('#layout_west_tree').tree({
			url : layout_west_tree_url,
			parentField : 'pid',
			lines : true,
			onClick : function(node) {
				if (node.attributes && node.attributes.url) {
					var url = '${ctx}' + node.attributes.url;
					addTab({
						url : url,
						title : node.text,
						iconCls : node.iconCls
					});
				}
			}
		});
	});
	
	function addTab(params) {
		var iframe = '<iframe src="' + params.url + '" frameborder="0" style="border:0;width:100%;height:98%;"></iframe>';
		var t = $('#index_tabs');
		var opts = {
			title : params.title,
			closable : true,
			iconCls : params.iconCls,
			content : iframe,
			border : false,
			fit : true
		};
		if (t.tabs('exists', opts.title)) {
			t.tabs('select', opts.title);
		} else {
			t.tabs('add', opts);
		}
	}
	
	function logout(){
		$.messager.confirm('提示','确定要退出?',function(r){
			if (r){
				progressLoad();
				$.post( '${ctx}/admin/logout', function(result) {
					if(result.success){
						progressClose();
						window.location.href='${ctx}/admin/index';
					}
				}, 'json');
			}
		});
	}

	function editUserPwd() {
		parent.$.modalDialog({
			title : '修改密码',
			width : 300,
			height : 250,
			href : '${ctx}/user/editPwdPage',
			buttons : [ {
				text : '修改',
				handler : function() {
					var f = parent.$.modalDialog.handler.find('#editUserPwdForm');
					f.submit();
				}
			} ]
		});
	}

	function showTab(){
		var url = '${ctx}/apply/begin';
		addTab({
			url : url,
			title : '起草申请',
			iconCls : 'icon_dic'
		});
	}

	function setPeopleStatusUI(){
		var url = '${ctx}/admin/setPeopleStatusUI';
		parent.$.modalDialog({
		title : '设置人员状态',
		width : 500,
		height : 200,
		href : url,
		buttons : [ {
			text : '确定',
			handler : function() {
				var f = parent.$.modalDialog.handler.find('#setPeopleStatusUIForm');
				f.submit();
			}
		} ]
	});
	}

	function showPeopleStatusDetail(){
		var url = '${ctx}/admin/showPeopleStatusDetailUI';
		parent.$.modalDialog({
			title : '人员休假状态总览',
			width : 900,
			height : 300,
			href : url,
			/* buttons : [ {
				text : '确定',
				handler : function() {
					var f = parent.$.modalDialog.handler.find('#setPeopleStatusUIForm');
					f.submit();
				}
			} ] */
		});
	}
</script>
<style type="text/css">
#aa{
	width: 99%;
	height: 99%;
}
#aa1{
	width: 99%;
	height: 95%;
}
#aa2{
	width: 99%;
	height: 99%;
}
#tableShow{
	width: 100%;
	height: 100%;
	border-spacing: 2px;
	border-width: 1px; 
}
#tableShow tr {
	width: 50px;
	/* height: 30px; */
}
#tableShow td {
	/* height: 30px; */
}
</style>
</head>
<body>
	<div id="loading" style="position: fixed;top: -50%;left: -50%;width: 200%;height: 200%;background: #fff;z-index: 100;overflow: hidden;">
		<img src="${ctx}/style/images/index/ajax-loader.gif" style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto;" />
	</div>
	<div id="index_layout">
		<div data-options="region:'north'" style=" overflow: hidden;" id="header">
			<span style="float: right; padding-right: 20px;">欢迎 <b>${sessionInfo.name}</b>&nbsp;&nbsp; <a href="javascript:void(0)" onclick="editUserPwd()" style="color: #fff">修改密码</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="logout()" style="color: #fff">安全退出</a> &nbsp;&nbsp;&nbsp;&nbsp; </span> <span class="header"></span>
		</div>
		<div data-options="region:'west',split:true" title="主导航" style="width: 200px; overflow: hidden;overflow-y:auto;">
			<div class="well well-small" style="padding: 10px 5px 5px 5px;">
				<ul id="layout_west_tree"></ul>
			</div>
		</div>
		<div data-options="region:'center'" style="overflow: hidden;">
			<div id="index_tabs" >
				<div title="首页" data-options="border:false">
					  
				    <div style="width: 100%;height: 100%">
						    <div id="aa1" title="行事日历" >  
						    	<div id="" style="">
										<!-- <span style="font-size: larger;vertical-align: middle;">亲们行事日历：</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
										<c:if test="${fn:contains(sessionInfo.resourceList, '/apply/begin/apply')}">
											<a style="vertical-align: middle;" id="btn" href="javascript:showTab()" class="easyui-linkbutton" >请假申请</a>
										</c:if>
										<c:if test="${fn:contains(sessionInfo.resourceList, '/apply/begin/statusSubmit')}">
											<a style="vertical-align: middle;" id="btn" href="javascript:setPeopleStatusUI()" class="easyui-linkbutton" >设置人员状态</a>
										</c:if>
										<a style="vertical-align: middle;" id="btn" href="javascript:showPeopleStatusDetail()" class="easyui-linkbutton" >休假总览</a>
								</div>
								<table id="tableShow" >
									<tbody>
										<tr bgcolor="#87CEEB">
											<td></td>
											<td width="30%"><font size="+1"> <b id="today"></b> </font></td>
											<td width="30%"><font size="+1"> <b id="tomorrow"></b> </font></td>
											<td width="30%"><font size="+1"> <b id="thedayaftertomorrow"></b></font></td>
										</tr>
										<tr style="height: 100%">
											<td bgcolor="#87CEEB" align="center"><font size="+1"><b>人员休假状态总览</b></font></td>
											<td bgcolor="#DDDDDD"><center class="timeNow"></center></td>
											<td bgcolor="#CCCCCC"><center class="timeTomorrow"></td>
											<td bgcolor="#DDDDDD"><center class="timeAfterTomorrow"></td>
										</tr>
									</tbody>
								</table>
						    </div>  
					</div>
				</div>
			</div>
		</div>
		<div data-options="region:'south',border:false" style="height: 30px; overflow: hidden;text-align: center;background-color: #daeef5">developer:ljb</div>
	</div>
</body>
</html>